package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;

    /*用户通用设置---读取*/
    @GetMapping("/settings")
    public ResponseEntity settings() {
        //调用service查询
        SettingsVo settingsVo = settingsService.settings();
        return ResponseEntity.ok(settingsVo);
    }

    /*设置陌生人问题---保存*/
    @PostMapping("questions")
    public ResponseEntity saveQuestions(@RequestBody Map map){
        //获取参数
        String content = (String) map.get("content");
        //调用service进行设置
        settingsService.saveQuestions(content);
        return ResponseEntity.ok(null);
    }

    /*通知设置---保存*/
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map){
        //调用service进行设置
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }

    /*黑名单---翻页列表*/
    @GetMapping("/blacklist")
    public ResponseEntity blacklist( @RequestParam(defaultValue = "1") int page,
                                     @RequestParam(defaultValue = "10") int size){
        //调用service查询
        PageResult pr=settingsService.blacklist(page,size);
        return ResponseEntity.ok(pr);
    }

    /*黑名单---移除*/
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId){
        //调用service删除黑名单
        settingsService.deleteBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }

}
